home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Games / InputSprocketTest / InputSprocketSimpleTest.cp next >
Encoding:
Text File  |  2000-09-28  |  52.4 KB  |  2,430 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        InputSprocketSimpleTest.cp
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998-1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                xxx put dri here xxx
  13.  
  14.         Other Contact:        xxx put other contact here xxx
  15.  
  16.         Technology:            xxx put technology here xxx
  17.  
  18.     Writers:
  19.  
  20.         (cjd)    Chris De Salvo
  21.         (BWS)    Brent Schorsch
  22.         (sjb)    Steve Bollinger
  23.  
  24.     Change History (most recent first):
  25.  
  26.       <SP63>     8/16/99    cjd        Fixing a type in the menus.  The event test said to hit Control
  27.                                     to exit.  It should have said Command.
  28.       <SP62>     12/1/98    BWS        Add test item: get element list for device, then count elements
  29.                                     of certain type bassing null, then get the elements
  30.       <SP61>     11/6/98    BWS        Add version in menutest
  31.       <SP60>    10/20/98    BWS        Quit and pause now different
  32.         <59>     7/17/98    BWS        fix come comments
  33.         <58>     7/17/98    BWS        add sample code header
  34.         <57>     7/17/98    BWS        fix needs list, other cleanup for GM SDK
  35.         <56>     7/16/98    BWS        fix some constants so works with latest header
  36.         <55>     6/18/98    sjb        InputSprocket.h comes from <> place
  37. */
  38.  
  39. /*************************************************************************************
  40.  
  41. File:      InputSprocketSimpleTest.cp
  42.  
  43. Copyright © 1996, 1997, 1998 Apple Computer, Inc., All Rights Reserved
  44.  
  45.  
  46. You may incorporate this sample code into your applications without
  47. restriction, though the sample code has been provided "AS IS" and the
  48. responsibility for its operation is 100% yours.  However, what you are
  49. not permitted to do is to redistribute the source as "DSC Sample Code"
  50. after having made changes. If you're going to re-distribute the source,
  51. we require that you make it clear in the source that the code was
  52. descended from Apple Sample Code, but that you've made changes.
  53.  
  54. *************************************************************************************/
  55.  
  56. #ifndef DEBUG_DRIVER
  57.     #define DEBUG_DRIVER 0
  58. #endif
  59.  
  60. #include <stdio.h>
  61. #include <stdlib.h>
  62.  
  63. #include <DeskBus.h>
  64.  
  65. #include <InputSprocket.h>
  66. #include <SIOUX.h>
  67. #include <CursorDevices.h>
  68. #include <LowMem.h>
  69. #include <FixMath.h>
  70.  
  71. // (default menu, if none defined) which test (AUTOTEST, DIALOGTEST or MENUTEST)
  72. #ifndef AUTOTEST
  73. #ifndef DIALOGTEST
  74. #ifndef    MENUTEST
  75. #define MENUTEST        1
  76. #endif
  77. #endif
  78. #endif
  79.  
  80. // set the other #defines to 0
  81. #ifndef AUTOTEST
  82. #define AUTOTEST        0
  83. #endif
  84.  
  85. #ifndef DIALOGTEST
  86. #define DIALOGTEST    0
  87. #endif
  88.  
  89. #ifndef    MENUTEST
  90. #define MENUTEST        0
  91. #endif
  92.  
  93. #if DEBUG_DRIVER
  94.     #include "InputSprocketDriver.h"
  95. #endif
  96.  
  97. const OSType kCreatorCode        = 'ISpT';
  98. const OSType kSubCreatorCode    = '0015';
  99.  
  100. #define    kResourceID_setl            128
  101.  
  102. enum
  103. {
  104.     kNeedIndex_XAxis = 1,
  105.     kNeedIndex_YAxis = 2,
  106.     kNeedIndex_DeltaAccelerationX = 11,
  107.     kNeedIndex_DeltaAccelerationY = 12,
  108.     kNeedCount = 13
  109. };
  110.  
  111. enum
  112. {
  113.     kIconSuiteID_XThrust         = 129, 
  114.     kIconSuiteID_YThrust         = 130,
  115.     kIconSuiteID_ZThrust         = 131,
  116.     kIconSuiteID_Look             = 159,
  117.     kIconSuiteID_Fire            = 141,
  118.     kIconSuiteID_SecondaryFire    = 142,
  119.     kIconSuiteID_ThrustForward    = 147,
  120.     kIconSuiteID_ThrustBackward    = 148,
  121.     kIconSuiteID_Pause            = 144,
  122.     kIconSuiteID_Scroll            = 140,
  123.     kIconSuiteID_DeltaX            = 256,
  124.     kIconSuiteID_DeltaY            = 257
  125. };
  126.  
  127. Boolean gIsSuspended = false;
  128. Boolean gKeyboardEnabled = false;
  129. ISpElementListReference gVirtualList = NULL;
  130. ISpElementReference gVirtualElements[kNeedCount] = {nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil};
  131.       
  132.  
  133.  
  134. static ISpNeed gNeeds[kNeedCount] =
  135. {
  136.     { "\pForward Thrust",    kIconSuiteID_ZThrust,         0,    1, kISpElementKind_Axis,        kISpElementLabel_Axis_ZAxis,        kISpNeedFlag_Axis_AlreadyButton,     0, 0, 0    },
  137.     { "\pSide Thrust",         kIconSuiteID_XThrust,        0,    0, kISpElementKind_Axis,        kISpElementLabel_Axis_XAxis,        0, 0, 0, 0    },
  138.     { "\pVertical Thrust",     kIconSuiteID_YThrust,         0,    0, kISpElementKind_Axis,        kISpElementLabel_Axis_YAxis,        0, 0, 0, 0    },
  139.     { "\pLook",             kIconSuiteID_Look,            0,    0, kISpElementKind_Movement,    kISpElementLabel_None,                0, 0, 0, 0    },
  140.     { "\pFire",             kIconSuiteID_Fire,            0,    0, kISpElementKind_Button,        kISpElementLabel_Btn_Fire,            0, 0, 0, 0    },
  141.     { "\pSecondary Fire",    kIconSuiteID_SecondaryFire,    0,    0, kISpElementKind_Button,        kISpElementLabel_Btn_SecondaryFire,    0, 0, 0, 0    },
  142.     { "\pThrust Forward",     kIconSuiteID_ThrustForward, 0,    1, kISpElementKind_Button,        kISpElementLabel_Btn_MoveForward,    kISpNeedFlag_Button_AlreadyAxis,     0, 0, 0    },
  143.     { "\pThrust Backward",     kIconSuiteID_ThrustBackward,0,    1, kISpElementKind_Button,        kISpElementLabel_Btn_MoveBackward,    kISpNeedFlag_Button_AlreadyAxis,     0, 0, 0    },
  144.     { "\pPause",             kIconSuiteID_Pause,         0,    0, kISpElementKind_Button,        kISpElementLabel_Btn_StartPause,    kISpNeedFlag_NoMultiConfig,         0, 0, 0    },
  145.     { "\pQuit",                 kIconSuiteID_Pause,         0,    0, kISpElementKind_Button,        kISpElementLabel_Btn_Quit,            kISpNeedFlag_NoMultiConfig,         0, 0, 0    },
  146.     { "\pScroll",             kIconSuiteID_Scroll,        0,    0, kISpElementKind_DPad,        kISpElementLabel_None,                0, 0, 0, 0                    },
  147.     { "\pDelta X",            kIconSuiteID_DeltaX,        0,    0, kISpElementKind_Delta,        kISpElementLabel_Delta_Cursor_X,            0, 0, 0, 0                    },
  148.     { "\pDelta Y",            kIconSuiteID_DeltaY,        0,    0, kISpElementKind_Delta,        kISpElementLabel_Delta_Cursor_Y,            0, 0, 0, 0                    }
  149. };
  150.  
  151. SInt32 gStep;
  152. char gStepId[255];
  153.  
  154. typedef Boolean (*ISpEventProcPtr) (EventRecord* inEvent);
  155.  
  156. Boolean ISpConfigureFilterProc(EventRecord *inEvent);
  157.  
  158. Boolean ISpConfigureFilterProc(EventRecord *inEvent)
  159. {
  160.     Boolean handled;
  161.     
  162.     handled = SIOUXHandleOneEvent(inEvent);
  163.  
  164.     return handled;
  165. }
  166.  
  167. static Boolean Progress(UInt32 inItr, UInt32 inTotal, UInt32 inNumReports, char *string)
  168. {
  169.     UInt32 everyNTimes = inTotal / inNumReports;
  170.     
  171.     if (everyNTimes == 0) { everyNTimes = 1; }
  172.     
  173.     if (inItr == 0) { return false; }
  174.     
  175.     if ((inItr % everyNTimes) == 0)
  176.     {
  177.         UInt32 percent = (inItr * 100) / inTotal;
  178.         sprintf(string, "%d%% [%d of %d]", percent, inItr, inTotal);
  179.         return true;
  180.     }
  181.     
  182.     return false;
  183. }
  184.  
  185. static void InitStep(char *msg)
  186. {
  187.     gStep = 0;
  188.     sprintf(gStepId, "%3d");
  189.     
  190.     if (msg == nil)
  191.     {
  192.         printf("step %s\n", gStepId);
  193.     }
  194.     else
  195.     {
  196.         printf("step %s %s\n",gStepId, msg);
  197.     }
  198. }
  199.  
  200. static void NextStep(char *msg)
  201. {
  202.     long this_app_memory;
  203.     long this_sys_memory;
  204.     static Boolean first_time = true;
  205.     static long last_app_memory;
  206.     static long last_sys_memory;
  207.  
  208.     gStep++;
  209.     sprintf(gStepId, "%3d", gStep);
  210.  
  211.     this_app_memory = FreeMem();
  212.     this_sys_memory = FreeMemSys();
  213.  
  214.     if (first_time)    
  215.     {
  216.         first_time = false;
  217.     }
  218.     else
  219.     {
  220.         long delta_app_memory = last_app_memory - this_app_memory;
  221.         long delta_sys_memory = last_sys_memory - this_sys_memory;
  222.         
  223.         printf("step %s ending app mem = %d sys mem = %d\n", gStepId, this_app_memory, this_sys_memory);
  224.         printf("step %s delta app mem = %d sys mem = %d\n", gStepId, delta_app_memory, delta_sys_memory);
  225.     }
  226.  
  227.     if (msg == nil)
  228.     {
  229.         printf("step %s\n", gStepId);
  230.     }
  231.     else
  232.     {
  233.         printf("step %s %s\n",gStepId, msg);
  234.     }
  235.  
  236.     printf("step %s starting app mem = %d sys mem = %d\n", gStepId, this_app_memory, this_sys_memory);
  237.  
  238.     last_app_memory = this_app_memory;
  239.     last_sys_memory = this_sys_memory;
  240. }
  241.  
  242.  
  243.  
  244. static void FailMsg(char *failure)
  245. {
  246.     printf("step %s FAILED reason = %s\n", gStepId, failure);
  247. }
  248.  
  249. static void FailCode(OSStatus errorCode)
  250. {
  251.     printf("step %s FAILED errorCode = %d\n", gStepId, errorCode);
  252. }
  253.  
  254.  
  255. #define FAILMSG(x) { FailMsg(x); return; }
  256. #define FAILCODE(x) { FailCode(x); return; }
  257.  
  258. #define FFAILMSG(x) { FailMsg(x); return false; }
  259. #define FFAILCODE(x) { FailCode(x); return false; }
  260.  
  261. static void StatusMsg(char *msg)
  262. {
  263.     printf("step %s status msg = %s\n",gStepId, msg);
  264. }
  265.  
  266. void ShowFourByte(OSType fourByte);
  267. void ShowFourByte(OSType fourByte)
  268. {
  269.     putchar(((fourByte & 0xff000000) >> 24));
  270.     putchar(((fourByte & 0x00ff0000) >> 16));
  271.     putchar(((fourByte & 0x0000ff00) >> 8));
  272.     putchar(((fourByte & 0x000000ff) >> 00));
  273. }
  274.  
  275. void ShowStr63(const Str63 &theStr);
  276. void ShowStr63(const Str63 &theStr)
  277. {
  278.     int i;
  279.     int len = theStr[0];
  280.     if (len > 63) { len = 63; }
  281.     
  282.     for(i=1; i <= len; i++)
  283.     {
  284.         putchar(theStr[i]);
  285.     }
  286. }
  287.  
  288. static void AppendStr63(char *string, const Str63 &theStr)
  289. {
  290.     char *c = string;
  291.     int i;
  292.     
  293.     // find the end of the string
  294.     while(*c != nil) { c++; }
  295.     
  296.     for(i = 1; i <= theStr[0]; i++)
  297.     {
  298.         *c = theStr[i];
  299.         c++;
  300.     }
  301.     
  302.     *c = 0;
  303. }
  304.  
  305. void PrintEvent(ISpElementEventPtr theEvent);
  306. void PrintEvent(ISpElementEventPtr theEvent)
  307. {
  308.     ISpElementInfo info;
  309.     ISpElement_GetInfo(theEvent->element, &info);
  310.     OSStatus status;
  311.     const char* s = "•UNKNOWN•";
  312.     
  313.     printf("when = [%lu] [%lu]\n", theEvent->when.hi, theEvent->when.lo);
  314.     
  315.     switch (info.theKind)
  316.     {
  317.         case kISpElementKind_Delta:
  318.             float inches = (Fixed) theEvent->data;
  319.             inches /= 0xffff;
  320.                 
  321.             printf("data = 0x%lx (%f inches) \n", theEvent->data, inches);
  322.         break;
  323.         case kISpElementKind_Button:
  324.             switch (theEvent->data)
  325.             {
  326.                 case 0:
  327.                     s = "released";
  328.                 break;
  329.                 
  330.                 case 1:
  331.                     s = "pressed";
  332.                 break;
  333.             }
  334.             
  335.             printf("data = 0x%lx (%s)\n", theEvent->data, s);
  336.         break;
  337.         
  338.         case kISpElementKind_DPad:
  339.             switch (theEvent->data)
  340.             {
  341.                 case kISpPadIdle:
  342.                     s = "kISpPadIdle";
  343.                 break;
  344.                 
  345.                 case kISpPadLeft:
  346.                     s = "kISpPadLeft";
  347.                 break;
  348.                 
  349.                 case kISpPadUpLeft:
  350.                     s = "kISpPadUpLeft";
  351.                 break;
  352.                 
  353.                 case kISpPadUp:
  354.                     s = "kISpPadUp";
  355.                 break;
  356.                 
  357.                 case kISpPadUpRight:
  358.                     s = "kISpPadUpRight";
  359.                 break;
  360.                 
  361.                 case kISpPadRight:
  362.                     s = "kISpPadRight";
  363.                 break;
  364.                 
  365.                 case kISpPadDownRight:
  366.                     s = "kISpPadDownRight";
  367.                 break;
  368.                 
  369.                 case kISpPadDown:
  370.                     s = "kISpPadDown";
  371.                 break;
  372.                 
  373.                 case kISpPadDownLeft:
  374.                     s = "kISpPadDownLeft";
  375.                 break;
  376.             }
  377.             
  378.             printf("data = 0x%lx (%s)\n", theEvent->data, s);
  379.         break;
  380.         
  381.         case kISpElementKind_Axis:
  382.             float temp1 = ((float) theEvent->data)/((float) 0xFFFFFFFFU);
  383.             float temp2 = 2.0*temp1-1.0;
  384.             
  385.             printf("data = 0x%lx (%f%) (%f%)\n", theEvent->data, temp1, temp2);
  386.         break;
  387.         
  388.         case kISpElementKind_Movement:
  389.             printf("data = 0x%lx\n", theEvent->data);
  390.             
  391.             ISpMovementData movementData;
  392.             if (ISpElement_GetComplexState(theEvent->element, sizeof(ISpMovementData), &movementData) == noErr)
  393.             {
  394.                 switch (movementData.direction)
  395.                 {
  396.                     case kISpPadIdle:
  397.                         s = "kISpPadIdle";
  398.                     break;
  399.                     
  400.                     case kISpPadLeft:
  401.                         s = "kISpPadLeft";
  402.                     break;
  403.                     
  404.                     case kISpPadUpLeft:
  405.                         s = "kISpPadUpLeft";
  406.                     break;
  407.                     
  408.                     case kISpPadUp:
  409.                         s = "kISpPadUp";
  410.                     break;
  411.                     
  412.                     case kISpPadUpRight:
  413.                         s = "kISpPadUpRight";
  414.                     break;
  415.                     
  416.                     case kISpPadRight:
  417.                         s = "kISpPadRight";
  418.                     break;
  419.                     
  420.                     case kISpPadDownRight:
  421.                         s = "kISpPadDownRight";
  422.                     break;
  423.                     
  424.                     case kISpPadDown:
  425.                         s = "kISpPadDown";
  426.                     break;
  427.                     
  428.                     case kISpPadDownLeft:
  429.                         s = "kISpPadDownLeft";
  430.                     break;
  431.                 }
  432.                 
  433.                 float horz = 2.0*(((float) movementData.xAxis)/((float) 0xFFFFFFFFU))-1.0;
  434.                 float vert = 2.0*(((float) movementData.yAxis)/((float) 0xFFFFFFFFU))-1.0;
  435.                 
  436.                 printf("state = (%f,%f) (%s)\n", horz, vert, s);
  437.             }
  438.         break;
  439.     }
  440.     
  441.     printf("element = 0x%lx\n", theEvent->element);
  442.     printf("refcon = %lx\n", theEvent->refCon);
  443.     
  444.     printf("label = ");
  445.     ShowFourByte(info.theLabel);
  446.     printf("\n");
  447.     
  448.     printf("kind = ");
  449.     ShowFourByte(info.theKind);
  450.     printf("\n");
  451.     
  452.     printf("string = ");
  453.     ShowStr63(info.theString);
  454.     printf("\n");
  455.     
  456.     {
  457.         UInt32 data;
  458.  
  459.         status = ISpElement_GetSimpleState(theEvent->element, &data);
  460.  
  461.         if (status == noErr) { printf("polled = %x\n",data); }
  462.     }
  463.     
  464.     printf("\n\n");
  465. }
  466.  
  467.  
  468. void PrintElementBlock(ISpElementReference *theElementReferences, UInt32 count);
  469. void PrintElementBlock(ISpElementReference *theElementReferences, UInt32 count)
  470. {
  471.     printf("count = %d\n");
  472.  
  473.     int itr;
  474.     
  475.     for(itr = 0; itr < count; itr++)
  476.     {
  477.         printf("    element #%d\n",itr);
  478.         
  479.         ISpElementInfo info;
  480.  
  481.         ISpElement_GetInfo(theElementReferences[itr], &info);
  482.  
  483.         printf("        label = ");
  484.         ShowFourByte(info.theLabel);
  485.         printf("\n");
  486.  
  487.         printf("        kind = ");
  488.         ShowFourByte(info.theKind);
  489.         printf("\n");
  490.  
  491.         printf("        string = ");
  492.         ShowStr63(info.theString);
  493.         printf("\n\n");
  494.     }
  495. }
  496.  
  497. // if whichList is NULL then we use the global list
  498. static void GetAndPrintEvents(ISpElementListReference whichList)
  499. {
  500.     OSErr err;
  501.     
  502.     if (whichList == NULL)
  503.     {
  504.         err = ISpGetGlobalElementList(&whichList);
  505.         if (err)
  506.         {
  507.             printf("••• ISpGetGlobalElementList returned error (%ld)\n",err);
  508.             return;
  509.         }
  510.     }
  511.  
  512.     err = ISpElementList_Flush(whichList);
  513.     if (err)
  514.     {
  515.         printf("••• ISpElementList_Flush returned error (%ld)\n",err);
  516.         return;
  517.     }
  518.  
  519.     printf("getting events (press command to end)\n");
  520.     
  521.     while(1)
  522.     {
  523.         ISpElementEvent event;
  524.         Boolean wasEvent;
  525.  
  526.         err = ISpElementList_GetNextEvent(whichList, sizeof(event), &event, &wasEvent);
  527.         if (err)
  528.         {
  529.             printf("••• ISpElementList_GetNextEvent returned error (%ld)\n",err);
  530.             return;
  531.         }
  532.  
  533.         if (wasEvent)
  534.         {
  535.             PrintEvent(&event);
  536.         }
  537.         
  538.         KeyMap theKeys;
  539.         GetKeys(theKeys);
  540.  
  541.         if ((theKeys[1] & 0x8000))
  542.         {
  543.             break;
  544.         }
  545.         
  546.         SIOUXHandleOneEvent(nil);
  547.       }
  548. }
  549.  
  550. static void TestListOfDevices(void)
  551. {
  552.     ISpDeviceReference theDevices[100];
  553.     UInt32 deviceCount;
  554.     UInt32 deviceBufferSize = 100;
  555.     UInt32 deviceItr;
  556.     OSErr err;
  557.     
  558.     err = ISpDevices_Extract(deviceBufferSize, &deviceCount, theDevices);
  559.     if (err)
  560.     {
  561.         printf("••• ISpDevices_Extract returned error (%ld)\n",err);
  562.         return;
  563.     }
  564.     
  565.     printf("# of devices = %ld\n",deviceCount);
  566.     for(deviceItr = 0; deviceItr < deviceCount; deviceItr++)
  567.     {
  568.         printf("    device #%ld\n",deviceItr);
  569.         ISpDeviceDefinition theDfn;
  570.         
  571.         err = ISpDevice_GetDefinition(theDevices[deviceItr], sizeof(ISpDeviceDefinition), &theDfn);
  572.         if (err)
  573.         {
  574.             printf("••• ISpDevice_GetDefinition returned error (%ld)\n",err);
  575.             return;
  576.         }
  577.         
  578.         printf("        name = ");
  579.         ShowStr63(theDfn.deviceName);
  580.         printf("\n");
  581.         
  582.         printf("        class = ");
  583.         ShowFourByte(theDfn.theDeviceClass);
  584.         printf("\n");
  585.  
  586.         printf("        device identifier = ");
  587.         ShowFourByte(theDfn.theDeviceIdentifier);
  588.         printf("\n");
  589.  
  590.         printf("        permanent id = %ld\n",theDfn.permanentID);
  591.         
  592.         printf("\n\n");
  593.     }
  594. }
  595.  
  596. static void TestElementList_ExtractByKind(void)
  597. {
  598.     ISpDeviceReference theDevices[100];
  599.     UInt32 deviceCount;
  600.     UInt32 deviceBufferSize = 100;
  601.     UInt32 deviceItr;
  602.     OSErr err;
  603.  
  604.     err = ISpDevices_Extract(deviceBufferSize, &deviceCount, theDevices);
  605.     if (err)
  606.     {
  607.         printf("••• ISpDevices_Extract returned error (%ld)\n",err);
  608.         return;
  609.     }
  610.     
  611.     printf("\n\nChoose a device:\n");
  612.     for(deviceItr = 0; deviceItr < deviceCount; deviceItr++)
  613.     {
  614.         printf("  %ld) ", deviceItr+1);
  615.  
  616.         ISpDeviceDefinition theDfn;
  617.         err = ISpDevice_GetDefinition(theDevices[deviceItr], sizeof(ISpDeviceDefinition), &theDfn);
  618.         if (err) 
  619.             printf("••• ISpDevice_GetDefinition returned error (%ld)", err);
  620.         
  621.         ShowStr63(theDfn.deviceName);
  622.         printf("\n");
  623.     }
  624.  
  625.     printf("Selection: ");
  626.     char theString[32];
  627.     gets (theString);
  628.     UInt32 theChoice = atoi(theString);
  629.     
  630.     if (theChoice < 1 || theChoice > deviceCount)
  631.     {
  632.         printf("••• Invalid choice (%ld)\n", theChoice);
  633.         return;
  634.     }
  635.     
  636.     ISpElementListReference deviceElementList = 0;
  637.     err = ISpDevice_GetElementList(theDevices[theChoice-1], &deviceElementList);
  638.     if (err)
  639.     {
  640.         printf("••• ISpDevice_GetElementList returned error (%ld)\n",err);
  641.         return;
  642.     }
  643.     printf("\nGot the element list for device %ld, (%lx)\n", theChoice, (UInt32) deviceElementList);
  644.  
  645.     printf("\nChoose a kind:\n");
  646.     printf("1) Button ('butn')\n");
  647.     printf("2) Direction Pad ('dpad')\n");
  648.     printf("3) Axis ('axis')\n");
  649.     printf("4) Delta ('dlta')\n");
  650.     printf("5) Movement ('move')\n");
  651.     printf("6) Virtual ('virt')\n");
  652.     printf("Selection: ");
  653.     
  654.     gets (theString);
  655.     theChoice = atoi(theString);
  656.     
  657.     ISpElementKind    theKind;
  658.     switch (theChoice)
  659.     {
  660.         case 1:    theKind = kISpElementKind_Button;     break;
  661.         case 2:    theKind = kISpElementKind_DPad;     break;
  662.         case 3:    theKind = kISpElementKind_Axis;     break;
  663.         case 4:    theKind = kISpElementKind_Delta;     break;
  664.         case 5:    theKind = kISpElementKind_Movement; break;
  665.         case 6:    theKind = kISpElementKind_Virtual;     break;
  666.         
  667.         default:
  668.             printf("••• Invalid choice (%ld)\n", theChoice);
  669.             return;
  670.     }
  671.     
  672.     UInt32 elementOfKindCount = 0;
  673.     
  674.     err = ISpElementList_ExtractByKind(deviceElementList, theKind, 0, &elementOfKindCount, nil);
  675.     if (err)
  676.     {
  677.         printf("••• ISpElementList_ExtractByKind returned error (%ld)\n",err);
  678.         return;
  679.     }
  680.     printf("%ld elements counted (with zero count null buffer)\n", elementOfKindCount);
  681.     
  682.     err = ISpElementList_ExtractByKind(deviceElementList, theKind, 0, &elementOfKindCount, nil);
  683.     if (err)
  684.     {
  685.         printf("••• ISpElementList_ExtractByKind returned error (%ld)\n",err);
  686.         return;
  687.     }
  688.     printf("%ld elements counted (with zero count null buffer)\n", elementOfKindCount);
  689.     
  690.     const UInt32    kElementListSize = 300;
  691.     ISpElementReference    elements[kElementListSize];
  692.  
  693.     err = ISpElementList_ExtractByKind(deviceElementList, theKind, 0, &elementOfKindCount, elements);
  694.     if (err)
  695.     {
  696.         printf("••• ISpElementList_ExtractByKind returned error (%ld)\n",err);
  697.         return;
  698.     }
  699.     printf("%ld elements counted (with zero count)\n", elementOfKindCount);
  700.  
  701.     err = ISpElementList_ExtractByKind(deviceElementList, theKind, 1, &elementOfKindCount, elements);
  702.     if (err)
  703.     {
  704.         printf("••• ISpElementList_ExtractByKind returned error (%ld)\n",err);
  705.         return;
  706.     }
  707.     printf("%ld elements counted (with one count)\n", elementOfKindCount);
  708.  
  709.     err = ISpElementList_ExtractByKind(deviceElementList, theKind, kElementListSize, &elementOfKindCount, elements);
  710.     if (err)
  711.     {
  712.         printf("••• ISpElementList_ExtractByKind returned error (%ld)\n",err);
  713.         return;
  714.     }
  715.     printf("%ld elements counted (with %ld count)\n", elementOfKindCount, kElementListSize);
  716.  
  717.     err = ISpElementList_ExtractByKind(deviceElementList, theKind, kElementListSize, &elementOfKindCount, elements);
  718.     if (err)
  719.     {
  720.         printf("••• ISpElementList_ExtractByKind returned error (%ld)\n",err);
  721.         return;
  722.     }
  723.     printf("%ld elements counted (with %ld count)\n", elementOfKindCount, kElementListSize);
  724.     
  725.     printf("\npress return key to continue\n");
  726.     gets (theString);
  727. }
  728.  
  729. static void TestListOfElements(void)
  730. {
  731.     ISpElementListReference globalList;
  732.     OSErr err;
  733.     
  734.     err = ISpGetGlobalElementList(&globalList);
  735.     if (err)
  736.     {
  737.         printf("••• ISpGetGlobalElementList returned error (%ld)\n",err);
  738.         return;
  739.     }
  740.     
  741.     ISpElementReference theElementReferences[200];
  742.     UInt32 bufferSize = 200;
  743.     UInt32 count;
  744.  
  745.     err = ISpElementList_Extract(globalList, bufferSize, &count, theElementReferences);
  746.     if (err)
  747.     {
  748.         printf("••• ISpElementList_Extract returned error (%ld)\n",err);
  749.         return;
  750.     }
  751.     
  752.     PrintElementBlock(theElementReferences, count);
  753. }
  754.  
  755.  
  756. static void TestListOfButtons(void)
  757. {
  758.     ISpElementListReference globalList;
  759.     OSErr err;
  760.     
  761.     err = ISpGetGlobalElementList(&globalList);
  762.     if (err)
  763.     {
  764.         printf("••• ISpGetGlobalElementList returned error (%ld)\n",err);
  765.         return;
  766.     }
  767.     
  768.     ISpElementReference theElementReferences[200];
  769.     UInt32 bufferSize = 200;
  770.     UInt32 count;
  771.  
  772.     err = ISpElementList_ExtractByKind(globalList, kISpElementKind_Button, bufferSize, &count, theElementReferences);
  773.     if (err)
  774.     {
  775.         printf("••• ISpElementList_Extract returned error (%ld)\n",err);
  776.         return;
  777.     }
  778.     
  779.     PrintElementBlock(theElementReferences, count);
  780. }
  781.  
  782.  
  783. static void TestListOfDPads(void)
  784. {
  785.     ISpElementListReference globalList;
  786.     OSErr err;
  787.     
  788.     err = ISpGetGlobalElementList(&globalList);
  789.     if (err)
  790.     {
  791.         printf("••• ISpGetGlobalElementList returned error (%ld)\n",err);
  792.         return;
  793.     }
  794.     
  795.     ISpElementReference theElementReferences[200];
  796.     UInt32 bufferSize = 200;
  797.     UInt32 count;
  798.  
  799.     err = ISpElementList_ExtractByKind(globalList, kISpElementKind_DPad, bufferSize, &count, theElementReferences);
  800.     if (err)
  801.     {
  802.         printf("••• ISpElementList_Extract returned error (%ld)\n",err);
  803.         return;
  804.     }
  805.     
  806.     PrintElementBlock(theElementReferences, count);
  807. }
  808.  
  809.  
  810. static void TestListOfAxes(void)
  811. {
  812.     ISpElementListReference globalList;
  813.     OSErr err;
  814.     
  815.     err = ISpGetGlobalElementList(&globalList);
  816.     if (err)
  817.     {
  818.         printf("••• ISpGetGlobalElementList returned error (%ld)\n",err);
  819.         return;
  820.     }
  821.     
  822.     ISpElementReference theElementReferences[200];
  823.     UInt32 bufferSize = 200;
  824.     UInt32 count;
  825.  
  826.     err = ISpElementList_ExtractByKind(globalList, kISpElementKind_Axis, bufferSize, &count, theElementReferences);
  827.     if (err)
  828.     {
  829.         printf("••• ISpElementList_Extract returned error (%ld)\n",err);
  830.         return;
  831.     }
  832.     
  833.     PrintElementBlock(theElementReferences, count);
  834. }
  835.  
  836.  
  837. static void TestListOfXAxes(void)
  838. {
  839.     ISpElementListReference globalList;
  840.     OSErr err;
  841.     
  842.     err = ISpGetGlobalElementList(&globalList);
  843.     if (err)
  844.     {
  845.         printf("••• ISpGetGlobalElementList returned error (%ld)\n",err);
  846.         return;
  847.     }
  848.     
  849.     ISpElementReference theElementReferences[200];
  850.     UInt32 bufferSize = 200;
  851.     UInt32 count;
  852.  
  853.     err = ISpElementList_ExtractByLabel(globalList, kISpElementLabel_Axis_XAxis, bufferSize, &count, theElementReferences);
  854.     if (err)
  855.     {
  856.         printf("••• ISpElementList_Extract returned error (%ld)\n",err);
  857.         return;
  858.     }
  859.     
  860.     PrintElementBlock(theElementReferences, count);
  861. }
  862.  
  863.  
  864. static void TestSuspend(void)
  865. {
  866.     OSErr err;
  867.     
  868.     err = ISpSuspend();
  869.     if (err)
  870.     {
  871.         printf("••• ISpSuspend returned error (%ld)\n",err);
  872.         return;
  873.     }
  874.     
  875.     gIsSuspended = true;
  876. }
  877.  
  878.  
  879. static void TestResume(void)
  880. {
  881.     OSErr err;
  882.     
  883.     err = ISpResume();
  884.     if (err)
  885.     {
  886.         printf("••• ISpResume returned error (%ld)\n",err);
  887.         return;
  888.     }
  889.     
  890.     gIsSuspended = false;
  891. }
  892.  
  893.  
  894. static void TestCreateNeeds(void)
  895. {
  896.     OSErr err;
  897.     
  898.     if (gVirtualList == NULL)
  899.     {
  900.         printf("creating virtual elements\n");
  901.         
  902.           err = ISpElement_NewVirtualFromNeeds(kNeedCount, gNeeds, gVirtualElements, 0);
  903.         if (err)
  904.         {
  905.             printf("••• ISpElement_NewVirtualFromNeeds returned error (%ld)\n",err);
  906.             return;
  907.         }
  908.         
  909.         err = ISpElementList_New(
  910.             kNeedCount,                // count
  911.             gVirtualElements,        // needs
  912.             &gVirtualList,            // virtual elements
  913.             0);                        // flags
  914.         if (err)
  915.         {
  916.             printf("••• ISpElementList_New returned error (%ld)\n",err);
  917.             return;
  918.         }
  919.               
  920.         err = ISpInit(kNeedCount,    // count
  921.                 gNeeds,                // needs
  922.                 gVirtualElements,    // virtual elements
  923.                 kCreatorCode,        // app
  924.                 kSubCreatorCode,    // sub (we are using as a versioning)
  925.                 0,                    // flags
  926.                 kResourceID_setl,    // set list resource id
  927.                 0);                    // reserved
  928.         if (err)
  929.         {
  930.             printf("••• ISpInit returned error (%ld)\n",err);
  931.             return;
  932.         }
  933.     }
  934. }
  935.  
  936.  
  937. static void TestDestroyNeeds(void)
  938. {
  939.     OSErr err;
  940.     
  941.     if (gVirtualList != NULL)
  942.     {
  943.         err = ISpElementList_Dispose(gVirtualList);
  944.         gVirtualList = NULL;
  945.         if (err)
  946.         {
  947.             printf("••• ISpElementList_Dispose returned error (%ld)\n",err);
  948.             return;
  949.         }
  950.         
  951.          err = ISpStop();
  952.         if (err)
  953.         {
  954.             printf("••• ISpStop returned error (%ld)\n",err);
  955.             return;
  956.         }
  957.         
  958.         err = ISpElement_DisposeVirtual(kNeedCount, gVirtualElements);
  959.         if (err)
  960.         {
  961.             printf("••• ISpElement_DisposeVirtual returned error (%ld)\n",err);
  962.             return;
  963.         }
  964.     }
  965. }
  966.  
  967.  
  968. static void TestNeedsEvents(void)
  969. {
  970.     TestCreateNeeds();
  971.     
  972.     if (gVirtualList != NULL)
  973.     {
  974.         GetAndPrintEvents(gVirtualList);
  975.     }
  976. }
  977.  
  978.  
  979. static void TestConfiguration(void)
  980. {
  981.     OSErr err;
  982.     
  983.     TestCreateNeeds();
  984.     
  985.     err = ISpConfigure(nil);
  986.     if (err)
  987.     {
  988.         printf("••• ISpConfigure returned error (%ld)\n",err);
  989.         return;
  990.     }
  991. }
  992.  
  993.  
  994. static void EnableDeviceClass(OSType deviceClass, Boolean enable)
  995. {
  996.     enum {
  997.         kDeviceList_COUNT = 100
  998.     };
  999.     
  1000.     OSStatus err;
  1001.     UInt32 count;
  1002.     ISpDeviceReference deviceList[kDeviceList_COUNT];
  1003.     
  1004.     // NOTE: This is not the correct way to handle the list count thing.  We
  1005.     // should actually call once with NULL for the device list, malloc a list of
  1006.     // that size, and call again.
  1007.     
  1008.     err = ISpDevices_ExtractByClass(
  1009.             deviceClass,
  1010.             kDeviceList_COUNT,
  1011.             &count,
  1012.             deviceList);
  1013.     
  1014.     if (err)
  1015.     {
  1016.         printf("••• ISpDevices_ExtractByClass returned error (%ld)\n",err);
  1017.         return;
  1018.     }
  1019.     
  1020.     if (count > kDeviceList_COUNT)
  1021.     {
  1022.         count = kDeviceList_COUNT;
  1023.     }
  1024.     
  1025.     if (enable)
  1026.     {
  1027.         err = ISpDevices_Activate(
  1028.                 count,
  1029.                 deviceList);
  1030.         
  1031.         if (err)
  1032.         {
  1033.             printf("••• ISpDevices_Activate returned error (%ld)\n",err);
  1034.             return;
  1035.         }
  1036.     }
  1037.     else
  1038.     {
  1039.         err = ISpDevices_Deactivate(
  1040.                 count,
  1041.                 deviceList);
  1042.         
  1043.         if (err)
  1044.         {
  1045.             printf("••• ISpDevices_Deactivate returned error (%ld)\n",err);
  1046.             return;
  1047.         }
  1048.     }
  1049.     
  1050.     if (deviceClass == kISpDeviceClass_Keyboard)
  1051.     {
  1052.         gKeyboardEnabled = enable;
  1053.     }
  1054. }
  1055.  
  1056. static void TestAllocateDeallocate(void)
  1057. {
  1058.     OSErr err = noErr;
  1059.     UInt32 count = 0;
  1060.     char theString[32];
  1061.     UInt32 itr;    
  1062.     ISpElementReference virtuals[kNeedCount];
  1063.     Boolean done = false;
  1064.     
  1065.     printf("allocate/dellocate how many times>");
  1066.     
  1067.     gets( theString );
  1068.     count = atoi( theString );
  1069.  
  1070.     printf("allocating/deallocating %ld times\n",count);
  1071.     
  1072.     for(itr = 0; itr < count; itr++)
  1073.     {
  1074.         if ((itr % 100) == 0) { putchar('.'); fflush(stdout);  }
  1075.         if ((itr % 1000) == 0) 
  1076.         {
  1077.             long normal = FreeMem();
  1078.             long system = FreeMemSys();
  1079.             printf("%ld / %ld (app = %ld) (sys = %ld) \n",itr,count,normal,system);
  1080.         }
  1081.     
  1082.         SIOUXHandleOneEvent(nil);
  1083.         
  1084.           err = ISpElement_NewVirtualFromNeeds(kNeedCount, gNeeds, virtuals, 0);
  1085.         
  1086.         if (err)
  1087.         {
  1088.             printf("••• itr = %d ISpElement_NewVirtualFromNeeds returned error (%ld)\n",itr, err);
  1089.             
  1090.             done = true;
  1091.         }
  1092.     
  1093.         err = ISpElement_DisposeVirtual(kNeedCount, virtuals);
  1094.     
  1095.         if (err)
  1096.         {
  1097.             printf("••• ISpElementList_Dispose returned error (%ld)\n",err);
  1098.             return;
  1099.         }
  1100.         
  1101.         if (done) { return; }
  1102.     }
  1103. }
  1104.  
  1105. #define MAX_ELEMENTS    1000
  1106. #define MAX_DATASIZE    1000
  1107.  
  1108.  
  1109. #if DEBUG_DRIVER
  1110. static void TestAllocatePushData(void)
  1111. {
  1112.     char theString[32];
  1113.     OSErr err = noErr;
  1114.     UInt32 elementCount = 0;
  1115.     UInt32 dataSize;
  1116.     UInt32 count;
  1117.     UInt32 elemItr, itr;
  1118.     ISpElementReference elements[MAX_ELEMENTS];
  1119.     UInt8 state[MAX_DATASIZE];
  1120.     
  1121.     printf("how many elements>");
  1122.     gets( theString );
  1123.     elementCount = atoi( theString );
  1124.  
  1125.     printf("data size>");
  1126.     gets( theString );
  1127.     dataSize = atoi( theString );
  1128.  
  1129.     printf("count>");
  1130.     gets( theString );
  1131.     count = atoi( theString );
  1132.  
  1133.     printf("%ld elements, data size = %ld, count = %ld\n", elementCount, dataSize, count);
  1134.     
  1135.     
  1136.     if ((elementCount > MAX_ELEMENTS) || (dataSize > MAX_DATASIZE))
  1137.     {
  1138.         printf("••• MAX_ELEMENTS = %d MAX_DATASIZE = %d\n",MAX_ELEMENTS,MAX_DATASIZE);
  1139.         return;
  1140.     }
  1141.  
  1142.     for(elemItr = 0; elemItr < elementCount; elemItr++)
  1143.     {
  1144.         err = ISpElement_NewVirtual(dataSize, &(elements[elemItr]), 0);
  1145.  
  1146.         if (err)
  1147.         {
  1148.             printf("••• ISpElement_NewVirtual returned error (%d)\n",err);
  1149.             
  1150.             err = ISpElement_DisposeVirtual(elemItr, elements);
  1151.             if (err)
  1152.             {
  1153.                 printf("••• ISpElement_DisposeVirtual returned error (%d)\n",err);
  1154.             }
  1155.             
  1156.             return;
  1157.         }
  1158.     }
  1159.     
  1160.     for(itr = 0; itr < count; itr++)
  1161.     {
  1162.         AbsoluteTime time = {0, TickCount() };
  1163.         
  1164.         if ((itr % 100) == 0) { printf("."); }
  1165.         if ((itr % 1000) == 0) 
  1166.         {
  1167.             long normal = FreeMem();
  1168.             long system = FreeMemSys();
  1169.             Ptr temp = NewPtr(1000);
  1170.             DisposePtr(temp);
  1171.             printf("%ld / %ld (app = %ld) (sys = %ld) \n",itr,count,normal,system);
  1172.             
  1173.         }
  1174.         
  1175.         SIOUXHandleOneEvent(nil);
  1176.         
  1177.         for(elemItr = 0; elemItr < elementCount; elemItr++)
  1178.         {
  1179.             err = ISpElement_PushComplexData(elements[elemItr], dataSize, &state, &time);
  1180.             
  1181.             if (err)
  1182.             {
  1183.                 printf("••• ISpElement_PushComplexData returned error (%d)\n",err);
  1184.                 return;
  1185.             }
  1186.         }
  1187.     }
  1188.  
  1189.     printf("\ndisposing elements\n");
  1190.     err = ISpElement_DisposeVirtual(elementCount, elements);
  1191.     if (err)
  1192.     {
  1193.         printf("••• ISpElement_DisposeVirtual returned error (%d)\n",err);
  1194.     }
  1195. }
  1196. #endif /* DEBUG_DRIVER */
  1197.  
  1198. static void TestArbitraryAllocate(void)
  1199. {
  1200.     char theString[32];
  1201.     OSErr err = noErr;
  1202.     UInt32 elementCount = 0;
  1203.     UInt32 dataSize;
  1204.     UInt32 elemItr;
  1205.     ISpElementReference elements[MAX_ELEMENTS];
  1206.     
  1207.     printf("how many elements>");
  1208.     gets( theString );
  1209.     elementCount = atoi( theString );
  1210.  
  1211.     printf("data size>");
  1212.     gets( theString );
  1213.     dataSize = atoi( theString );
  1214.  
  1215.  
  1216.     printf("%ld elements, data size = %ld\n", elementCount, dataSize);    
  1217.     
  1218.     if ((elementCount > MAX_ELEMENTS) || (dataSize > MAX_DATASIZE))
  1219.     {
  1220.         printf("••• MAX_ELEMENTS = %d MAX_DATASIZE = %d\n",MAX_ELEMENTS,MAX_DATASIZE);
  1221.         return;
  1222.     }
  1223.  
  1224.     printf("allocating elements\n");
  1225.     for(elemItr = 0; elemItr < elementCount; elemItr++)
  1226.     {
  1227.         err = ISpElement_NewVirtual(dataSize, &(elements[elemItr]), 0);
  1228.  
  1229.         if (err)
  1230.         {
  1231.             printf("••• ISpElement_NewVirtual returned error (%d)\n",err);
  1232.             
  1233.             err = ISpElement_DisposeVirtual(elemItr, elements);
  1234.             if (err)
  1235.             {
  1236.                 printf("••• ISpElement_DisposeVirtual returned error (%d)\n",err);
  1237.             }
  1238.             
  1239.             return;
  1240.         }
  1241.     }
  1242.  
  1243.     printf("\ndisposing elements\n");
  1244.     err = ISpElement_DisposeVirtual(elementCount, elements);
  1245.     if (err)
  1246.     {
  1247.         printf("••• ISpElement_DisposeVirtual returned error (%d)\n",err);
  1248.     }
  1249. }
  1250.  
  1251. #define MTemp 0x828
  1252. #define RawMouse 0x82c
  1253. #define CrsrNewCouple 0x8ce
  1254.  
  1255. static void TestAcceleration(void)
  1256. {
  1257.     TestCreateNeeds();
  1258.  
  1259.     ShowCursor();
  1260.     Point where =  * ( Point * ) RawMouse;
  1261.  
  1262.     float deltaX = 0;
  1263.     float deltaY = 0;
  1264.     
  1265.     while(1)
  1266.     {
  1267.         gVirtualElements[kNeedIndex_XAxis];
  1268.         gVirtualElements[kNeedIndex_YAxis];
  1269.         
  1270.         UInt32 forward;
  1271.         UInt32 side;
  1272.         OSStatus status;
  1273.         float temp;
  1274.         SInt8 amt;
  1275.         
  1276.         status = ISpElement_GetSimpleState(gVirtualElements[kNeedIndex_XAxis], &forward);
  1277.  
  1278.         if (status == noErr)
  1279.         {
  1280.             temp = forward;
  1281.             temp -= kISpAxisMiddle;
  1282.             temp /= kISpAxisMiddle;
  1283.             temp *= 25;
  1284.             
  1285.             deltaX += temp;
  1286.             
  1287.             if (deltaX >= 1) 
  1288.             {
  1289.                 amt = deltaX;
  1290.                 where.h += amt;
  1291.                 deltaX -= amt;
  1292.             }
  1293.             else if (deltaX <= -1)
  1294.             {
  1295.                 amt = -deltaX;
  1296.                 where.h -= amt;
  1297.                 deltaX += amt;
  1298.             }
  1299.         }
  1300.         
  1301.         status = ISpElement_GetSimpleState(gVirtualElements[kNeedIndex_YAxis], &side);
  1302.  
  1303.         if (status == noErr)
  1304.         {
  1305.             temp = side;
  1306.             temp -= kISpAxisMiddle;
  1307.             temp /= kISpAxisMiddle;
  1308.             temp *= -25;
  1309.             
  1310.             deltaY += temp;
  1311.  
  1312.             if (deltaY >= 1) 
  1313.             {
  1314.                 amt = deltaY;
  1315.                 where.v += amt;
  1316.                 deltaY -= amt;
  1317.             }
  1318.             else if (deltaY <= -1)
  1319.             {
  1320.                 amt = -deltaY;
  1321.                 where.v -= amt;
  1322.                 deltaY += amt;
  1323.             }
  1324.  
  1325.         }
  1326.                 
  1327.         HideCursor();
  1328.         
  1329.         * ( Point * ) RawMouse = where ;
  1330.         * ( Point * ) MTemp = where ;
  1331.         * ( short * ) CrsrNewCouple = -1 ;
  1332.         
  1333.         ShowCursor();
  1334.     
  1335.         KeyMap theKeys;
  1336.         GetKeys(theKeys);
  1337.  
  1338.         if ((theKeys[1] & 0x8000))
  1339.         {
  1340.             break;
  1341.         }
  1342.         
  1343.         unsigned long aLong = ::TickCount();
  1344.         
  1345.         while (aLong == TickCount()) { ; }
  1346.     }
  1347. }
  1348.  
  1349. static void TestAcceleration2(void)
  1350. {
  1351.     TestCreateNeeds();
  1352.  
  1353.     ShowCursor();
  1354.     
  1355.     while(1)
  1356.     {
  1357.         Point where = * ( Point * ) RawMouse;
  1358.  
  1359.         Fixed horzPos = where.h * fixed1;
  1360.         Fixed vertPos = where.v * fixed1;
  1361.  
  1362.         Fixed horzDelta = 0;
  1363.         Fixed vertDelta = 0;
  1364.         OSStatus status;
  1365.         
  1366.         status = ISpElement_GetSimpleState(gVirtualElements[kNeedIndex_DeltaAccelerationX],    (UInt32 *) &horzDelta);
  1367.         status = ISpElement_GetSimpleState(gVirtualElements[kNeedIndex_DeltaAccelerationY],    (UInt32 *) &vertDelta);
  1368.         
  1369.         if ((horzDelta != 0) || (vertDelta != 0))
  1370.         {
  1371.             HideCursor();
  1372.             
  1373.             horzPos += 72 * horzDelta;
  1374.             vertPos -= 72 * vertDelta;
  1375.             
  1376.             where.h = horzPos / fixed1;
  1377.             where.v = vertPos / fixed1;
  1378.         
  1379.             * ( Point * ) RawMouse = where ;
  1380.             * ( Point * ) MTemp = where ;
  1381.             * ( short * ) CrsrNewCouple = -1 ;
  1382.             
  1383.             ShowCursor();
  1384.         }
  1385.     
  1386.         KeyMap theKeys;
  1387.         GetKeys(theKeys);
  1388.  
  1389.         if ((theKeys[1] & 0x8000))
  1390.         {
  1391.             break;
  1392.         }
  1393.     }
  1394. }
  1395.  
  1396. #define FVERIFY(x)    if (x) { FailCode(x); return false; }
  1397. #define FVERIFY2(x, y)    if (x) {    char VERIFY2_DEBUG_STATUS[512]; \
  1398.                                     sprintf(VERIFY2_DEBUG_STATUS,"%s got %d",y,x); \
  1399.                                      FailMsg(VERIFY2_DEBUG_STATUS); return false; }
  1400.  
  1401. // true if ExtractByClass works
  1402. // false otherwise
  1403. // 
  1404. static Boolean VerifyExtractByClass(void)
  1405. {
  1406.     ISpDeviceClass deviceClass;
  1407.     const UInt32 kNumDeviceClass = 8;
  1408.     ISpDeviceClass kDeviceClassArray[kNumDeviceClass] = { kISpDeviceClass_SpeechRecognition,
  1409.                                     kISpDeviceClass_Mouse,
  1410.                                     kISpDeviceClass_Keyboard,
  1411.                                     kISpDeviceClass_Joystick,
  1412.                                     kISpDeviceClass_Wheel,
  1413.                                     kISpDeviceClass_Pedals,
  1414.                                     kISpDeviceClass_Levers,
  1415.                                     'junk'
  1416.                                     };
  1417.     UInt32 deviceClassItr;
  1418.     OSStatus err;
  1419.     UInt32 result1, result2, result3;
  1420.     const UInt32 kFixedBufferSize = 100;
  1421.     ISpDeviceReference fixedBuffer[kFixedBufferSize] = { 0 } ;
  1422.     ISpDeviceReference *exactBuffer;
  1423.     UInt32 verifyItr;
  1424.     char debug_status[255];
  1425.     
  1426.     NextStep("broad band ISpDevices_ExtractByClass verification");
  1427.     
  1428.     for(deviceClassItr = 0; deviceClassItr < kNumDeviceClass; deviceClassItr++)
  1429.     {    
  1430.         deviceClass = kDeviceClassArray[deviceClassItr];
  1431.         
  1432.         sprintf(debug_status, "device class = %c%c%c%c", (deviceClass & 0xff000000) >> 24, (deviceClass & 0xff0000) >> 16, 
  1433.                 (deviceClass & 0xff00) >> 8, (deviceClass & 0xff) >> 0);
  1434.         StatusMsg(debug_status);
  1435.         
  1436.         // result 1
  1437.         err = ISpDevices_ExtractByClass(deviceClass, 0, &result1, NULL);
  1438.         if (err) { FailMsg("ISpDevices_ExtractByClass failed with a null buffer"); return false; }
  1439.         
  1440.         sprintf(debug_status, "found %d devices of that type",result1);
  1441.         StatusMsg(debug_status);
  1442.         
  1443.         // result 2
  1444.         err = ISpDevices_ExtractByClass(deviceClass, kFixedBufferSize, &result2, fixedBuffer);
  1445.         if (err) { FailMsg("ISpDevices_ExtractByClass failed with a fixed buffer"); return false; }
  1446.         for(verifyItr = 0; ((verifyItr < result2) && (verifyItr < kFixedBufferSize)); verifyItr ++)
  1447.         {
  1448.             StatusMsg("verifying on list 2");
  1449.             if (fixedBuffer[verifyItr] == nil) 
  1450.             {
  1451.                 FailMsg("ISpDevices_ExtractByClass failed to verify non nil with a fixed buffer");
  1452.                 return false;
  1453.             }
  1454.         }
  1455.         
  1456.         // result 3
  1457.         exactBuffer = (ISpDeviceReference *) NewPtrClear(sizeof(ISpDeviceReference) * result1);
  1458.         if (exactBuffer == nil) { FailMsg("Problem with test program not the sprocket, test program needs more memory!"); return false; }
  1459.         err = ISpDevices_ExtractByClass(deviceClass, result1, &result3, exactBuffer);
  1460.         if (err) { FailMsg("ISpDevices_ExtractByClass failed with an exact buffer"); return false; }
  1461.         for(verifyItr = 0; verifyItr < result3; verifyItr ++)
  1462.         {
  1463.             StatusMsg("verifying on list 3");
  1464.             if (exactBuffer[verifyItr] == nil) 
  1465.             {
  1466.                 FailMsg("ISpDevices_ExtractByClass failed to verify non nil with an exact buffer");
  1467.                 return false;
  1468.             }
  1469.         }
  1470.         DisposePtr((Ptr) exactBuffer);
  1471.         
  1472.         if ((result1 != result2) || (result1 != result3))
  1473.         {
  1474.             FailMsg("the three results were not all the same!");
  1475.             return false;
  1476.         }
  1477.     }
  1478.     
  1479.     return true;
  1480. }
  1481.  
  1482.  
  1483. static Boolean VerifyActivateDeactive(void)
  1484. {
  1485.     const UInt32 kMaxDevices = 100;
  1486.     ISpDeviceReference devices[kMaxDevices];
  1487.     OSStatus err;
  1488.     UInt32 numDevices;
  1489.     char debug_status[512];
  1490.     NextStep("Running Enable/Disable test");
  1491.     UInt32 deviceItr;
  1492.     UInt32 enableDisableItr;
  1493.     const UInt32 kNumEnableDisableAttempts = 100;
  1494.     
  1495.     err = ISpDevices_Extract(kMaxDevices, &numDevices, devices);
  1496.     FVERIFY2(err,"ISpDevices_Extract")
  1497.         
  1498.     for(deviceItr = 0; deviceItr < numDevices; deviceItr++)
  1499.     {
  1500.         ISpDeviceReference thisDevice = devices[deviceItr];
  1501.         Boolean wasActive;
  1502.         ISpDeviceDefinition thisDefinition;
  1503.         
  1504.         err = ISpDevice_IsActive(thisDevice, &wasActive);
  1505.         FVERIFY2(err, "ISpDevice_IsActive");
  1506.         
  1507.         if (wasActive)
  1508.         {
  1509.             err = ISpDevices_Deactivate(1, &thisDevice);
  1510.             FVERIFY2(err, "ISpDevices_Deactivate")
  1511.         }
  1512.         
  1513.         err = ISpDevice_GetDefinition(thisDevice, sizeof(ISpDeviceDefinition), &thisDefinition);
  1514.         FVERIFY2(err, "ISpDevice_GetDefinition")
  1515.         
  1516.         sprintf(debug_status,"working on device ");
  1517.         AppendStr63(debug_status, thisDefinition.deviceName);
  1518.         StatusMsg(debug_status);
  1519.         
  1520.         for(enableDisableItr = 0; enableDisableItr < kNumEnableDisableAttempts; enableDisableItr++)
  1521.         {
  1522.             if (Progress(enableDisableItr, kNumEnableDisableAttempts, 10, debug_status))
  1523.             {
  1524.                 StatusMsg(debug_status);
  1525.             }
  1526.             
  1527.             err = ISpDevices_Activate(1, &thisDevice);
  1528.             FVERIFY2(err, "ISpDevices_Activate")
  1529.  
  1530.             err = ISpDevices_Deactivate(1, &thisDevice);
  1531.             FVERIFY2(err, "ISpDevices_Deactivate")            
  1532.         }
  1533.         
  1534.         StatusMsg("100%");
  1535.         
  1536.         if (wasActive)
  1537.         {
  1538.             err = ISpDevices_Activate(1, &thisDevice);
  1539.             FVERIFY2(err, "ISpDevices_Activate")
  1540.         }
  1541.     }    
  1542.  
  1543.     return true;    
  1544. }
  1545.  
  1546. static void WaitForAnyKey(void)
  1547. {
  1548.     KeyMap theKeyMap;
  1549.     
  1550.     GetKeys(theKeyMap);
  1551.     
  1552.     while((theKeyMap[0] == 0) && (theKeyMap[1] == 0) && (theKeyMap[2] == 0) && (theKeyMap[3] == 0))
  1553.     {
  1554.         SIOUXHandleOneEvent(nil);
  1555.         GetKeys(theKeyMap);
  1556.     }
  1557. }
  1558.  
  1559. #define VERIFY(x)    if (x) { FailCode(x); return; }
  1560.  
  1561.  
  1562.  
  1563. static void AutoTest(void)
  1564. {
  1565.     OSStatus err;
  1566.     char debug_status[512];
  1567.     debug_status;
  1568.     Boolean success;
  1569.  
  1570.     InitStep("press any key to begin AutoTest");
  1571.     WaitForAnyKey();
  1572.  
  1573.     NextStep("getting the version of input sprocket");
  1574.     {
  1575.         NumVersion version = ISpGetVersion();
  1576.  
  1577.         sprintf(debug_status, "version = %x %x %x %x\n",version.majorRev, version.minorAndBugRev, version.stage, version.nonRelRev);
  1578.         StatusMsg(debug_status);
  1579.     }    
  1580.     
  1581.     NextStep("verifying that this is the first initialization");
  1582.     {
  1583.         if (gVirtualList != NULL)
  1584.         {
  1585.             FailMsg("this was not the first time a test was run for this launch of the application");
  1586.             return;
  1587.         }
  1588.     }
  1589.     
  1590.     NextStep("starting up");
  1591.     {
  1592.         err = ISpStartup();
  1593.         VERIFY(err);
  1594.     }
  1595.     
  1596.     NextStep("looping on startup / shutdown");
  1597.     {
  1598.         const UInt32 kStartShutAttempts = 20;
  1599.         UInt32 startShutItr;
  1600.                 
  1601.         for(startShutItr = 0; startShutItr < kStartShutAttempts; startShutItr++)
  1602.         {
  1603.             err = ISpShutdown();
  1604.             VERIFY(err)
  1605.  
  1606.             err = ISpStartup();
  1607.             VERIFY(err);
  1608.  
  1609.             if (Progress(startShutItr, kStartShutAttempts, 10, debug_status))
  1610.             {
  1611.                 StatusMsg(debug_status);
  1612.             }
  1613.         }
  1614.     }
  1615.         
  1616.     NextStep("single ISpSuspend (low level)");
  1617.     err = ISpSuspend();
  1618.     VERIFY(err);
  1619.  
  1620.     NextStep("single ISpResume (low level)");
  1621.     err = ISpResume();
  1622.     VERIFY(err);
  1623.  
  1624.     NextStep("testing suspend/resume repeatedly (low level)");
  1625.     {
  1626.         UInt32 kSuspendResumeLLCount = 1000;
  1627.         UInt32 suspendResumeLLItr;
  1628.                 
  1629.         for(suspendResumeLLItr = 0; suspendResumeLLItr < kSuspendResumeLLCount;  suspendResumeLLItr++)
  1630.         {
  1631.             if (Progress(suspendResumeLLItr, kSuspendResumeLLCount, 5, debug_status))
  1632.             {
  1633.                 StatusMsg(debug_status);
  1634.             }
  1635.             err = ISpSuspend();
  1636.             VERIFY(err);
  1637.             
  1638.             err = ISpResume();
  1639.             VERIFY(err);
  1640.         }        
  1641.     }
  1642.  
  1643.     NextStep("looping on startup / shutdown w/ a suspend in the middle");
  1644.     {
  1645.         const UInt32 kStartShutAttempts = 20;
  1646.         UInt32 startShutItr;
  1647.                 
  1648.         for(startShutItr = 0; startShutItr < kStartShutAttempts; startShutItr++)
  1649.         {
  1650.             if (Progress(startShutItr, kStartShutAttempts, 10, debug_status))
  1651.             {
  1652.                 StatusMsg(debug_status);
  1653.             }
  1654.  
  1655.             err = ISpSuspend();
  1656.             VERIFY(err);
  1657.  
  1658.             err = ISpShutdown();
  1659.             VERIFY(err)
  1660.  
  1661.             err = ISpStartup();
  1662.             VERIFY(err);
  1663.         }
  1664.     }
  1665.  
  1666.     NextStep("creating virtual elements");
  1667.       {
  1668.           err = ISpElement_NewVirtualFromNeeds(kNeedCount, gNeeds, gVirtualElements, 0);
  1669.         VERIFY(err)
  1670.     }
  1671.     
  1672.     NextStep("looping on disposing/recreating elements");
  1673.     {
  1674.         const UInt32 kDisposeCreateVirtualAttempts = 1000;
  1675.         UInt32 disposeCreateItr;
  1676.         
  1677.         for(disposeCreateItr = 0; disposeCreateItr < kDisposeCreateVirtualAttempts; disposeCreateItr++)
  1678.         {
  1679.         
  1680.             err = ISpElement_DisposeVirtual(kNeedCount, gVirtualElements);
  1681.             VERIFY(err)
  1682.  
  1683.               err = ISpElement_NewVirtualFromNeeds(kNeedCount, gNeeds, gVirtualElements, 0);
  1684.             VERIFY(err)
  1685.  
  1686.             if (Progress(disposeCreateItr, kDisposeCreateVirtualAttempts, 10, debug_status))
  1687.             {
  1688.                 StatusMsg(debug_status);
  1689.             }
  1690.         }
  1691.     }
  1692.     
  1693.     NextStep("creating an element list");
  1694.     {
  1695.         err = ISpElementList_New(
  1696.             kNeedCount,                // count
  1697.             gVirtualElements,        // needs
  1698.             &gVirtualList,            // virtual elements
  1699.             0);                        // flags
  1700.     
  1701.         VERIFY(err)
  1702.     }
  1703.     
  1704.     NextStep("initializing input sprocket once");
  1705.     {
  1706.         err = ISpInit(kNeedCount,    // count
  1707.                 gNeeds,                // needs
  1708.                 gVirtualElements,    // virtual elements
  1709.                 kCreatorCode,        // app
  1710.                 kSubCreatorCode,    // sub
  1711.                 0,                    // flags
  1712.                 kResourceID_setl,    // set list resource id
  1713.                 0);                    // version
  1714.  
  1715.         VERIFY(err)
  1716.     }
  1717.     
  1718.     NextStep("looping on ISpInit / ISpStop");
  1719.     {
  1720.         const UInt32 kStartStopAttempts = 20;
  1721.         UInt32 startStopItr;
  1722.                 
  1723.         err = ISpStop();
  1724.         VERIFY(err)
  1725.  
  1726.         for(startStopItr = 0; startStopItr < kStartStopAttempts; startStopItr++)
  1727.         {
  1728.             if (Progress(startStopItr, kStartStopAttempts, 10, debug_status))
  1729.             {
  1730.                 StatusMsg(debug_status);
  1731.             }
  1732.  
  1733.             err = ISpInit(kNeedCount, gNeeds, gVirtualElements, kCreatorCode, kSubCreatorCode, 0, kResourceID_setl, 0);
  1734.             VERIFY(err);
  1735.  
  1736.             err = ISpStop();
  1737.             VERIFY(err)
  1738.         }
  1739.     
  1740.         err = ISpInit(kNeedCount, gNeeds, gVirtualElements, kCreatorCode, kSubCreatorCode, 0, kResourceID_setl, 0);
  1741.         VERIFY(err);
  1742.     }
  1743.     
  1744.     NextStep("counting all the devices (verying size buffer) + isActive");
  1745.     {
  1746.         const UInt32 maxExtractBufferSize = 1000;
  1747.         ISpDeviceReference buffer[maxExtractBufferSize];
  1748.         UInt32 deviceCount;
  1749.         UInt32 bufferSizeItr;
  1750.         UInt32 bufferItr;
  1751.         Boolean isActive;
  1752.         
  1753.         for(bufferSizeItr = 0; bufferSizeItr < 1000; bufferSizeItr++)
  1754.         {
  1755.             if (Progress(bufferSizeItr, maxExtractBufferSize, 5, debug_status))
  1756.             {
  1757.                 StatusMsg(debug_status);
  1758.             }
  1759.  
  1760.         
  1761.             // step 1 put the buffer into a known state
  1762.             for(bufferItr = 0; bufferItr < maxExtractBufferSize; bufferItr++)
  1763.             {
  1764.                 buffer[bufferItr] = (ISpDeviceReference) 0xd0d0babe;
  1765.             }
  1766.             
  1767.             // step 2 call extract
  1768.             err = ISpDevices_Extract(bufferSizeItr, &deviceCount, buffer);
  1769.  
  1770.             if (!err)
  1771.             {
  1772.                 for(bufferItr = 0; ((bufferItr < deviceCount) && (bufferItr < bufferSizeItr)); bufferItr++)
  1773.                 {
  1774.                     if ((UInt32) buffer[bufferItr] == 0xd0d0babe)
  1775.                     {
  1776.                         sprintf(debug_status, "bufferSizeItr = %d deviceCount = %d, bufferItr = %d",bufferSizeItr, deviceCount, bufferItr);
  1777.                         StatusMsg(debug_status);
  1778.                     }
  1779.                     
  1780.                     err = ISpDevice_IsActive(buffer[bufferItr], &isActive);
  1781.                     if (err) { break; }
  1782.                 }
  1783.             }
  1784.             VERIFY(err)    
  1785.  
  1786.             // step 3 verify the buffer contents
  1787.             for(; bufferItr < maxExtractBufferSize; bufferItr++)
  1788.             {
  1789.                 if (((UInt32) buffer[bufferItr]) != 0xd0d0babe) 
  1790.                 {
  1791.                     sprintf(debug_status,"spilled off the end loc = %d cnt = %d",bufferItr,deviceCount);
  1792.                     StatusMsg(debug_status);
  1793.                 }
  1794.             }
  1795.         }
  1796.     }
  1797.             
  1798.     NextStep("verifying all the devices (100 size buffer) w/ ISpDevice_GetDefinition");
  1799.     {
  1800.         UInt32 deviceCount;
  1801.         ISpDeviceReference buffer[100];
  1802.         UInt32 itr;
  1803.         ISpDeviceDefinition outStruct;
  1804.         
  1805.         err = ISpDevices_Extract(100, &deviceCount, buffer);
  1806.         
  1807.         if (!err)
  1808.         {
  1809.             for(itr = 0; itr < deviceCount; itr++)
  1810.             {
  1811.                 err = ISpDevice_GetDefinition(buffer[itr], sizeof(ISpDeviceDefinition), &outStruct);
  1812.                 if (err) { break; }
  1813.             }
  1814.         }
  1815.                     
  1816.         VERIFY(err)
  1817.     }
  1818.     
  1819.     NextStep("searching for all the devices of class kISpDeviceClass_Mouse");
  1820.     {
  1821.         UInt32 deviceCount;
  1822.         ISpDeviceReference buffer[100];
  1823.         
  1824.         err = ISpDevices_ExtractByClass(kISpDeviceClass_Mouse, 100, &deviceCount, buffer);
  1825.         
  1826.         VERIFY(err)
  1827.     }
  1828.  
  1829.     NextStep("searching for all the devices of class kISpDeviceClass_Keyboard");
  1830.     {
  1831.         UInt32 deviceCount;
  1832.         ISpDeviceReference buffer[100];
  1833.         
  1834.         err = ISpDevices_ExtractByClass(kISpDeviceClass_Keyboard, 100, &deviceCount, buffer);
  1835.         
  1836.         VERIFY(err)
  1837.     }
  1838.  
  1839.     NextStep("searching for all the devices of class kISpDeviceClass_Joystick");
  1840.     {
  1841.         UInt32 deviceCount;
  1842.         ISpDeviceReference buffer[100];
  1843.         
  1844.         err = ISpDevices_ExtractByClass(kISpDeviceClass_Joystick, 100, &deviceCount, buffer);
  1845.         
  1846.         VERIFY(err)
  1847.     }
  1848.     
  1849.     success = VerifyExtractByClass();
  1850.     if (!success) { return; }
  1851.     
  1852.     success = VerifyActivateDeactive();
  1853.     if (!success) { return; }
  1854.     
  1855.     NextStep("bringing up the configuration screen (devices disabled, dialog warning you there are no devices is OK)");
  1856.     {
  1857.         err = ISpConfigure(nil);
  1858.         
  1859.         VERIFY(err)
  1860.     }
  1861.     
  1862.     NextStep("enabling all the devices of class kISpDeviceClass_Mouse");
  1863.     {
  1864.         UInt32 deviceCount;
  1865.         ISpDeviceReference buffer[100];
  1866.  
  1867.         err = ISpDevices_ExtractByClass(kISpDeviceClass_Mouse, 100, &deviceCount, buffer);
  1868.         
  1869.         if (!err)
  1870.         {
  1871.             err = ISpDevices_Activate(deviceCount, buffer);
  1872.         }
  1873.         
  1874.         VERIFY(err)
  1875.     }
  1876.  
  1877.     NextStep("enabling all the devices of class kISpDeviceClass_Keyboard");
  1878.     {
  1879.         UInt32 deviceCount;
  1880.         ISpDeviceReference buffer[100];
  1881.         
  1882.         err = ISpDevices_ExtractByClass(kISpDeviceClass_Keyboard, 100, &deviceCount, buffer);
  1883.         
  1884.         if (!err)
  1885.         {
  1886.             err = ISpDevices_Activate(deviceCount, buffer);
  1887.         }
  1888.  
  1889.         VERIFY(err)
  1890.     }
  1891.     
  1892.     NextStep("bringing up the configuration screen");
  1893.     {
  1894.         err = ISpConfigure(nil);
  1895.         
  1896.         VERIFY(err)
  1897.     }
  1898.     
  1899.     NextStep("bringing up the configuration screen w/ filter proc");
  1900.     {
  1901.         err = ISpConfigure(ISpConfigureFilterProc);
  1902.         
  1903.         VERIFY(err)
  1904.     }
  1905.     
  1906.     NextStep("getting the global list");
  1907.     {
  1908.         ISpElementListReference globalList;
  1909.         
  1910.         err = ISpGetGlobalElementList(&globalList);
  1911.  
  1912.         VERIFY(err)
  1913.     }
  1914.     
  1915.     NextStep("flushing the global list (and pausing)");
  1916.     {
  1917.         ISpElementListReference globalList;
  1918.         unsigned long ticks;
  1919.         const number_of_seconds_to_pause = 2;
  1920.         
  1921.         err = ISpGetGlobalElementList(&globalList);
  1922.  
  1923.         if (!err)
  1924.         {
  1925.             ticks = TickCount();
  1926.             ticks += number_of_seconds_to_pause * 60;
  1927.             
  1928.             while(ticks > TickCount())
  1929.             {
  1930.                 err = ISpElementList_Flush(globalList);
  1931.                 if (err) { break; }
  1932.             }
  1933.         }
  1934.  
  1935.         VERIFY(err)
  1936.     }
  1937.     
  1938.     NextStep("testing getting events, please press a button or move an axis");
  1939.     {
  1940.         ISpElementListReference globalList;
  1941.         ISpElementEvent event;
  1942.         Boolean wasEvent;
  1943.         
  1944.         err = ISpGetGlobalElementList(&globalList);
  1945.         
  1946.         if (!err)
  1947.         {
  1948.             wasEvent = false;
  1949.             
  1950.             while(!wasEvent)
  1951.             {
  1952.                 err = ISpElementList_GetNextEvent(globalList, sizeof(ISpElementEvent), &event, &wasEvent);
  1953.                 
  1954.                 if (err == kISpBufferToSmallErr) { err = noErr; }
  1955.                 
  1956.                 if (err) { break; }
  1957.             }
  1958.         }
  1959.         
  1960.         VERIFY(err)
  1961.     }
  1962.  
  1963.  
  1964.     NextStep("flushing the need list (and pausing)");
  1965.     {
  1966.         unsigned long ticks;
  1967.         const number_of_seconds_to_pause = 2;
  1968.         
  1969.         ticks = TickCount();
  1970.         ticks += number_of_seconds_to_pause * 60;
  1971.         
  1972.         while(ticks > TickCount())
  1973.         {
  1974.             err = ISpElementList_Flush(gVirtualList);
  1975.             if (err) { break; }
  1976.         }
  1977.  
  1978.         VERIFY(err)
  1979.     }
  1980.     
  1981.     NextStep("testing getting need events, please press a configured button or move an axis (escape should always work)");
  1982.     {
  1983.         ISpElementEvent event;
  1984.         Boolean wasEvent;
  1985.         
  1986.         wasEvent = false;
  1987.         
  1988.         while(!wasEvent)
  1989.         {
  1990.             err = ISpElementList_GetNextEvent(gVirtualList, sizeof(ISpElementEvent), &event, &wasEvent);
  1991.             
  1992.             if (err) { break; }
  1993.         }
  1994.         
  1995.         VERIFY(err)
  1996.     }
  1997.     
  1998.     NextStep("single ISpSuspend");
  1999.     err = ISpSuspend();
  2000.     VERIFY(err);
  2001.  
  2002.     NextStep("single ISpResume");
  2003.     err = ISpResume();
  2004.     VERIFY(err);
  2005.  
  2006.     NextStep("testing suspend/resume repeatedly (high level)");
  2007.     {
  2008.         UInt32 kSuspendResumeCount = 1000;
  2009.         UInt32 suspendResumeItr;
  2010.                 
  2011.         err = ISpSuspend();
  2012.         VERIFY(err);
  2013.             
  2014.         err = ISpResume();
  2015.         VERIFY(err);
  2016.  
  2017.  
  2018.         for(suspendResumeItr = 0; suspendResumeItr < kSuspendResumeCount;  suspendResumeItr++)
  2019.         {
  2020.             if (Progress(suspendResumeItr, kSuspendResumeCount, 5, debug_status))
  2021.             {
  2022.                 StatusMsg(debug_status);
  2023.             }
  2024.             err = ISpSuspend();
  2025.             VERIFY(err);
  2026.             
  2027.             err = ISpResume();
  2028.             VERIFY(err);
  2029.         }        
  2030.     }
  2031.  
  2032.     NextStep("disabling all the devices of class kISpDeviceClass_Mouse");
  2033.     {
  2034.         UInt32 deviceCount;
  2035.         ISpDeviceReference buffer[100];
  2036.  
  2037.         err = ISpDevices_ExtractByClass(kISpDeviceClass_Mouse, 100, &deviceCount, buffer);
  2038.         
  2039.         if (!err)
  2040.         {
  2041.             err = ISpDevices_Deactivate(deviceCount, buffer);
  2042.         }
  2043.         
  2044.         VERIFY(err)
  2045.     }
  2046.  
  2047.     NextStep("disabling all the devices of class kISpDeviceClass_Keyboard");
  2048.     {
  2049.         UInt32 deviceCount;
  2050.         ISpDeviceReference buffer[100];
  2051.         
  2052.         err = ISpDevices_ExtractByClass(kISpDeviceClass_Keyboard, 100, &deviceCount, buffer);
  2053.         
  2054.         if (!err)
  2055.         {
  2056.             err = ISpDevices_Deactivate(deviceCount, buffer);
  2057.         }
  2058.  
  2059.         
  2060.         VERIFY(err)
  2061.     }
  2062.     
  2063.     NextStep("stopping input sprocket");
  2064.     {
  2065.         err = ISpStop();
  2066.         
  2067.         VERIFY(err)
  2068.     }
  2069. }
  2070.  
  2071. #if AUTOTEST
  2072. void main(void)
  2073. {
  2074.     // tell SIOUX to shut up
  2075.     SIOUXSettings.autocloseonquit = true;
  2076.     SIOUXSettings.asktosaveonclose = false;
  2077.  
  2078.     AutoTest();
  2079.     
  2080.     UInt32 who_cares;    
  2081.     scanf("%d",&who_cares);
  2082. }
  2083. #endif
  2084.  
  2085. #if DIALOGTEST
  2086. void main(void)
  2087. {
  2088.     OSErr err = noErr;
  2089.     
  2090.     NextStep("verifying that this is the first initialization");
  2091.     {
  2092.         if (gVirtualList != NULL)
  2093.         {
  2094.             FailMsg("this was not the first time a test was run for this launch of the application");
  2095.             return;
  2096.         }
  2097.     }
  2098.     
  2099.     NextStep("creating virtual elements");
  2100.       {
  2101.           err = ISpElement_NewVirtualFromNeeds(kNeedCount, gNeeds, gVirtualElements, 0);
  2102.     
  2103.         VERIFY(err)
  2104.     }
  2105.     
  2106.     NextStep("creating an element list");
  2107.     {
  2108.         err = ISpElementList_New(
  2109.             kNeedCount,                // count
  2110.             gVirtualElements,        // needs
  2111.             &gVirtualList,            // virtual elements
  2112.             0);                        // flags
  2113.     
  2114.         VERIFY(err)
  2115.     }
  2116.     
  2117.     NextStep("initializing input sprocket once");
  2118.     {
  2119.         err = ISpInit(kNeedCount,    // count
  2120.                 gNeeds,                // needs
  2121.                 gVirtualElements,    // virtual elements
  2122.                 kCreatorCode,        // app
  2123.                 kSubCreatorCode,    // sub
  2124.                 0,                    // flags
  2125.                 kResourceID_setl,    // set list resource id
  2126.                 0);                    // version
  2127.  
  2128.         VERIFY(err)
  2129.     }
  2130.     
  2131.     NextStep("enabling all the devices of class kISpDeviceClass_Mouse");
  2132.     {
  2133.         UInt32 deviceCount;
  2134.         ISpDeviceReference buffer[100];
  2135.  
  2136.         err = ISpDevices_ExtractByClass(kISpDeviceClass_Mouse, 100, &deviceCount, buffer);
  2137.         
  2138.         if (!err)
  2139.         {
  2140.             err = ISpDevices_Activate(deviceCount, buffer);
  2141.         }
  2142.         
  2143.         VERIFY(err)
  2144.     }
  2145.  
  2146.     NextStep("enabling all the devices of class kISpDeviceClass_Keyboard");
  2147.     {
  2148.         UInt32 deviceCount;
  2149.         ISpDeviceReference buffer[100];
  2150.         
  2151.         err = ISpDevices_ExtractByClass(kISpDeviceClass_Keyboard, 100, &deviceCount, buffer);
  2152.         
  2153.         if (!err)
  2154.         {
  2155.             err = ISpDevices_Activate(deviceCount, buffer);
  2156.         }
  2157.  
  2158.         VERIFY(err)
  2159.     }
  2160.     
  2161.     NextStep("enabling all the devices of class kISpDeviceClass_SpeechRecognition");
  2162.     {
  2163.         UInt32 deviceCount;
  2164.         ISpDeviceReference buffer[100];
  2165.         
  2166.         err = ISpDevices_ExtractByClass(kISpDeviceClass_SpeechRecognition, 100, &deviceCount, buffer);
  2167.         
  2168.         if (!err)
  2169.         {
  2170.             err = ISpDevices_Activate(deviceCount, buffer);
  2171.         }
  2172.  
  2173.         VERIFY(err)
  2174.     }
  2175.  
  2176.     NextStep("bringing up the configuration screen");
  2177.     {
  2178.         err = ISpConfigure(nil);
  2179.         
  2180.         VERIFY(err)
  2181.     }
  2182.     
  2183.     NextStep("disabling all the devices of class kISpDeviceClass_Mouse");
  2184.     {
  2185.         UInt32 deviceCount;
  2186.         ISpDeviceReference buffer[100];
  2187.  
  2188.         err = ISpDevices_ExtractByClass(kISpDeviceClass_Mouse, 100, &deviceCount, buffer);
  2189.         
  2190.         if (!err)
  2191.         {
  2192.             err = ISpDevices_Deactivate(deviceCount, buffer);
  2193.         }
  2194.         
  2195.         VERIFY(err)
  2196.     }
  2197.  
  2198.     NextStep("disabling all the devices of class kISpDeviceClass_Keyboard");
  2199.     {
  2200.         UInt32 deviceCount;
  2201.         ISpDeviceReference buffer[100];
  2202.         
  2203.         err = ISpDevices_ExtractByClass(kISpDeviceClass_Keyboard, 100, &deviceCount, buffer);
  2204.         
  2205.         if (!err)
  2206.         {
  2207.             err = ISpDevices_Deactivate(deviceCount, buffer);
  2208.         }
  2209.  
  2210.         
  2211.         VERIFY(err)
  2212.     }
  2213.     NextStep("stopping input sprocket");
  2214.     {
  2215.         err = ISpStop();
  2216.         
  2217.         VERIFY(err)
  2218.     }
  2219.     
  2220.     NextStep("shutting down InputSprocket");
  2221.     err = ISpShutdown();
  2222.     VERIFY(err)
  2223. }
  2224. #endif
  2225. #if MENUTEST
  2226. void main(void)
  2227. {
  2228.     OSErr err = noErr;
  2229.     
  2230.     // tell SIOUX to shut up
  2231.     SIOUXSettings.autocloseonquit = true;
  2232.     SIOUXSettings.asktosaveonclose = false;
  2233.     
  2234.     printf("starting up...\n");
  2235.     
  2236.     NumVersion version = ISpGetVersion();
  2237.     printf("version = %x %x %x %x\n",version.majorRev, version.minorAndBugRev, version.stage, version.nonRelRev);
  2238.  
  2239.     NextStep("starting up InputSprocket");
  2240.     err = ISpStartup();
  2241.     VERIFY(err);
  2242.  
  2243.     Boolean theDoneFlag = false;
  2244.     
  2245.     EnableDeviceClass(kISpDeviceClass_SpeechRecognition, true);
  2246.     
  2247.     while( !theDoneFlag )
  2248.     {
  2249.         UInt32 theChoice;
  2250.         
  2251.         printf("\n\n\n############################################################\n");
  2252.         if (gIsSuspended)
  2253.         {
  2254.             printf("• SUSPENDED •\n");
  2255.         }
  2256.         
  2257.         if (gVirtualList != NULL)
  2258.         {
  2259.             printf("• NEEDS ARE ACTIVE •\n");
  2260.         }
  2261.         
  2262.         printf("Please select from the following tests:\n");        
  2263.         printf("\t 1. Exit\n");
  2264.         printf("\t 2. Run all tests automatically\n");
  2265.         printf("\t 3. Test ISpElementList_ExtractByKind\n");
  2266.         printf("\t 4. List all devices\n");
  2267.         printf("\t 5. List all elements\n");
  2268.         printf("\t 6. List all buttons\n");
  2269.         printf("\t 7. List all directional pads\n");
  2270.         printf("\t 8. List all axes\n");
  2271.         printf("\t 9. List all X-axes\n");
  2272.         printf("\t10. Get events (stop when Command key pressed)\n");
  2273.         printf("\t11. Suspend\n");
  2274.         printf("\t12. Resume\n");
  2275.         printf("\t13. Create needs\n");
  2276.         printf("\t14. Destroy needs\n");
  2277.         printf("\t15. Get needs events\n");
  2278.         printf("\t16. Configuration dialog\n");
  2279.         printf("\t17. Enable mouse and keyboard\n");
  2280.         printf("\t18. Disable mouse and keyboard\n");
  2281.         printf("\t19. Reinitialize ADB bus\n");
  2282.         printf("\t30. Allocate/Deallocate test\n");
  2283.         #if DEBUG_DRIVER
  2284.             printf("\t31. TestAllocatePushData test\n");
  2285.         #endif
  2286.         printf("\t32. TestArbitraryAllocate test\n");
  2287.         printf("\t33. TestAccelration\n");
  2288.         printf("\t34. Enable speech\n");
  2289.         printf("\t35. Disable speech\n");
  2290.         printf("\t36. Acceleration test # 2\n");
  2291.         
  2292.         printf("\n\tSelection: ");
  2293.         
  2294.         Boolean keyboardEnabled = gKeyboardEnabled;
  2295.         if (keyboardEnabled)
  2296.         {
  2297.             EnableDeviceClass(kISpDeviceClass_Keyboard, false);
  2298.         }
  2299.         
  2300.         char theString[32];
  2301.         gets( theString );
  2302.         theChoice = atoi( theString );
  2303.         
  2304.         if (keyboardEnabled)
  2305.         {
  2306.             EnableDeviceClass(kISpDeviceClass_Keyboard, true);
  2307.         }
  2308.         
  2309.         printf("\n\n");
  2310.         
  2311.         switch( theChoice )
  2312.         {
  2313.             case 1:
  2314.                 theDoneFlag = true;
  2315.                 break;
  2316.                 
  2317.             case 2:
  2318.                 AutoTest();
  2319.                 break;
  2320.                 
  2321.             case 3:
  2322.                 TestElementList_ExtractByKind();
  2323.                 break;
  2324.                 
  2325.             case 4:
  2326.                 TestListOfDevices();
  2327.                 break;            
  2328.             
  2329.             case 5:
  2330.                 TestListOfElements();
  2331.                 break;            
  2332.             
  2333.             case 6:
  2334.                 TestListOfButtons();
  2335.                 break;            
  2336.             
  2337.             case 7:
  2338.                 TestListOfDPads();
  2339.                 break;            
  2340.             
  2341.             case 8:
  2342.                 TestListOfAxes();
  2343.                 break;            
  2344.             
  2345.             case 9:
  2346.                 TestListOfXAxes();
  2347.                 break;            
  2348.             
  2349.             case 10:
  2350.                 GetAndPrintEvents(NULL);
  2351.                 break;            
  2352.             
  2353.             case 11:
  2354.                 TestSuspend();
  2355.                 break;            
  2356.             
  2357.             case 12:
  2358.                 TestResume();
  2359.                 break;            
  2360.             
  2361.             case 13:
  2362.                 TestCreateNeeds();
  2363.                 break;            
  2364.             
  2365.             case 14:
  2366.                 TestDestroyNeeds();
  2367.                 break;            
  2368.             
  2369.             case 15:
  2370.                 TestNeedsEvents();
  2371.                 break;            
  2372.             
  2373.             case 16:
  2374.                 TestConfiguration();
  2375.                 break;            
  2376.             
  2377.             case 17:
  2378.                 EnableDeviceClass(kISpDeviceClass_Mouse, true);
  2379.                 EnableDeviceClass(kISpDeviceClass_Keyboard, true);
  2380.                 break;            
  2381.             
  2382.             case 18:
  2383.                 EnableDeviceClass(kISpDeviceClass_Mouse, false);
  2384.                 EnableDeviceClass(kISpDeviceClass_Keyboard, false);
  2385.                 break;
  2386.             
  2387.             case 19:
  2388.                 ADBReInit();
  2389.                 break;
  2390.                 
  2391.             case 30:
  2392.                 TestAllocateDeallocate();
  2393.                 break;
  2394.         
  2395.         #if DEBUG_DRIVER
  2396.             case 31:
  2397.                 TestAllocatePushData();
  2398.                 break;
  2399.         #endif
  2400.             
  2401.             case 32:
  2402.                 TestArbitraryAllocate();
  2403.                 break;
  2404.             
  2405.             case 33:
  2406.                 TestAcceleration();
  2407.                 break;
  2408.                 
  2409.             case 34:
  2410.                 EnableDeviceClass(kISpDeviceClass_SpeechRecognition, true);
  2411.                 break;            
  2412.             
  2413.             case 35:
  2414.                 EnableDeviceClass(kISpDeviceClass_SpeechRecognition, false);
  2415.                 break;
  2416.             
  2417.             case 36:
  2418.                 TestAcceleration2();
  2419.                 break;
  2420.  
  2421.             default:
  2422.                 printf("\nhuh?\n");
  2423.                 break;            
  2424.         }
  2425.         
  2426.         printf("\nThank you, please drive through.\n");
  2427.     }
  2428. }
  2429. #endif
  2430.